﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;

namespace SuperQuiz.Utils
{
    [ContentProperty(Name="Converters")]
    public class ValueConverterGroup : IValueConverter
    {
        private readonly ObservableCollection<IValueConverter> converters = new ObservableCollection<IValueConverter>();

        public ObservableCollection<IValueConverter> Converters
        {
            get { return this.converters; }
        }

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            foreach (var converter in Converters)
            {
                value = converter.Convert(value, targetType, parameter, language);
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            for (int i = Converters.Count - 1; i >= 0; i--)
            {
                var converter = Converters[i];
                value = converter.Convert(value, targetType, parameter, language);
            }
            return value;
        }
    }
}
